package com.lenovo.agricultureclient.ui.fragment;

import com.lenovo.agricultureclient.ClientApp;
import com.lenovo.agricultureclient.request.BaseRequest;
import com.lenovo.agricultureclient.request.RequestThread;
import com.lenovo.agricultureclient.ui.activity.MainActivity;

import android.app.Fragment;
import android.os.Bundle;
/**
 * 本项目中的基础fragment
 * @author zongbingwu
 *
 */
public class AppBaseFragment extends Fragment 
{
	protected ClientApp mApp;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MainActivity mainActivity = (MainActivity)getActivity();
		mApp = (ClientApp)mainActivity.getApplication();
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) 
	{
		super.onActivityCreated(savedInstanceState);
		if(mApp == null){
			MainActivity mainActivity = (MainActivity)getActivity();
			mApp = (ClientApp)mainActivity.getApplication();
		}
	}
	//显示加载等待提示框
	public void showLoadDialog()
	{
		MainActivity mainActivity = (MainActivity)getActivity();
		mainActivity.showLoadDialog();
	}
	//关闭加载等待提示框
	public void dismissLoadDialog()
	{
		MainActivity mainActivity = (MainActivity)getActivity();
		mainActivity.dismissLoadDialog();
	}
	//开启一次性的请求线程，请求结束以后，线程就停止
	public RequestThread startRequest(BaseRequest request)
	{
		MainActivity mainActivity = (MainActivity)getActivity();
		return mainActivity.startRequest(request);
	}
	//显示带有“确定”按钮的提示框
	public void showAlertDialog(String title, String message)
	{
		MainActivity mainActivity = (MainActivity)getActivity();
		mainActivity.showAlertDialog(title,message);
	}
	//设置activity标题
	public void setTitle(String title)
	{
		MainActivity mainActivity = (MainActivity)getActivity();
		mainActivity.setTitle(title);
	}

}
